package com.stylefeng.guns.modular.platform.controller;
 
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.platform.model.BuyerDemand;
import com.stylefeng.guns.modular.platform.service.IBuyerDemandService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-07-13 19:10:29
 */
@Controller
@RequestMapping("/buyerDemand")
public class BuyerDemandController extends BaseController {

    private String PREFIX = "/platform/buyerDemand/";

    @Autowired
    private IBuyerDemandService buyerDemandService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "buyerDemand.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/buyerDemand_add")
    public String buyerDemandAdd() {
        return PREFIX + "buyerDemand_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/buyerDemand_update/{buyerDemandId}")
    public String buyerDemandUpdate(@PathVariable Integer buyerDemandId, Model model) {
        BuyerDemand buyerDemand = buyerDemandService.selectById(buyerDemandId);
        model.addAttribute("item",buyerDemand);
        LogObjectHolder.me().set(buyerDemand);
        return PREFIX + "buyerDemand_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(BuyerDemand buyerDemand) {
    	EntityWrapper<BuyerDemand> wp =null;
    	if(StringUtils.isNotBlank(buyerDemand.getAppName())){
    		wp= new EntityWrapper<BuyerDemand>();
    		wp.like("app_name", buyerDemand.getAppName());
    	}
        return buyerDemandService.selectList(wp);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(BuyerDemand buyerDemand) {
        buyerDemandService.insert(buyerDemand);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer buyerDemandId) {
        buyerDemandService.deleteById(buyerDemandId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BuyerDemand buyerDemand) {
        buyerDemandService.updateById(buyerDemand);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{buyerDemandId}")
    @ResponseBody
    public Object detail(@PathVariable("buyerDemandId") Integer buyerDemandId) {
        return buyerDemandService.selectById(buyerDemandId);
    }
}
